package com.zhang.serviceorder.controller;

import com.zhang.internalcommon.constant.HeaderParamConstants;
import com.zhang.internalcommon.dto.OrderInfo;
import com.zhang.internalcommon.dto.OrderRequest;
import com.zhang.internalcommon.dto.ResponseResult;
import com.zhang.serviceorder.service.OrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 类功能描述
 *
 * @author Kye
 * @date 2025-04-16
 */
@RequestMapping("/order")
@RestController
@Slf4j
public class OrderController {

	@Autowired
	private OrderInfoService orderInfoService;

	/**
	 * 创建订单
	 *
	 * @param orderRequest       请求体
	 * @param httpServletRequest 请求头
	 * @return
	 */
	@PostMapping("/add")
	public ResponseResult addOrder(@RequestBody OrderRequest orderRequest, HttpServletRequest httpServletRequest) {
		// String deviceCode = httpServletRequest.getHeader(HeaderParamConstants.DEVICE_CODE);
		// orderRequest.setDeviceCode(deviceCode);

		return orderInfoService.addOrder(orderRequest);
	}

	/**
	 * 创建预约单
	 *
	 * @param orderRequest
	 * @return
	 */
	@PostMapping("/book")
	public ResponseResult book(@RequestBody OrderRequest orderRequest, HttpServletRequest httpServletRequest) {

		log.info("service-order" + orderRequest.getAddress());
		return orderInfoService.book(orderRequest);
	}

	/**
	 * 订单详情
	 *
	 * @param orderId
	 * @return
	 */
	@GetMapping("/detail")
	public ResponseResult<OrderInfo> detail(Long orderId) {
		return orderInfoService.detail(orderId);
	}

	/**
	 * 接乘客
	 *
	 * @param orderRequest
	 * @return
	 */
	@PostMapping("/to-pick-up-passenger")
	public ResponseResult toPickUpPassenger(@RequestBody OrderRequest orderRequest) {
		return orderInfoService.toPickUpPassenger(orderRequest);
	}

	@PostMapping("/arrived-departure")
	public ResponseResult arrivedDeparture(@RequestBody OrderRequest orderRequest) {
		return orderInfoService.arrivedDeparture(orderRequest);
	}

	/**
	 * 司机接到乘客
	 *
	 * @param orderRequest
	 * @return
	 */
	@PostMapping("/pick-up-passenger")
	public ResponseResult pickUpPassenger(@RequestBody OrderRequest orderRequest) {
		return orderInfoService.pickUpPassenger(orderRequest);
	}

	/**
	 * 乘客到达目的地，行程终止
	 *
	 * @param orderRequest
	 * @return
	 */
	@PostMapping("/passenger-getoff")
	public ResponseResult passengerGetoff(@RequestBody OrderRequest orderRequest) {
		return orderInfoService.passengerGetoff(orderRequest);
	}

	/**
	 * 司机发起收款
	 *
	 * @param orderRequest
	 * @return
	 */
	@PostMapping("/push-pay-info")
	public ResponseResult pushPayInfo(@RequestBody OrderRequest orderRequest) {
		return orderInfoService.pushPayInfo(orderRequest);
	}

	/**
	 * 支付订单 通过支付页面回调这个方法
	 *
	 * @param orderRequest
	 * @return
	 */
	@PostMapping("/pay")
	public ResponseResult pay(@RequestBody OrderRequest orderRequest) {
		return orderInfoService.pay(orderRequest);
	}

	/**
	 * 取消订单
	 *
	 * @param orderId
	 * @param identity
	 * @return
	 */
	@PostMapping("/cancel")
	public ResponseResult cancel(Long orderId, String identity) {

		return orderInfoService.cancel(orderId, identity);
	}

	@GetMapping("/current")
	public ResponseResult current(String phone , String identity){
		return orderInfoService.current(phone , identity);
	}


	// @Autowired
//    @Qualifier("grabBySingleRedisService")
//    @Qualifier("grabByMultiRedisService")
//    @Qualifier("grabByRedisDiyService")
//    @Qualifier("grabByRedisLuaService")
	// 默认用这个
	// @Qualifier("grabByRedissonBasicService")
//    @Qualifier("grabByRedissonBasicYamlService")
//    @Qualifier("grabByRedissonMasterSlaveYamlService")
//    @Qualifier("grabByRedissonSentinelYamlService")
//    @Qualifier("grabByRedissonClusterYamlService")
//    @Qualifier("grabByRedissonRedLockService")
//    @Qualifier("grabByZookeeperDiyService")
//    @Qualifier("grabByZookeeperCuratorService")
// 	private GrabService grabService;


	// /**
	//  * 司机抢单
	//  * @param driverGrabRequest
	//  * @return
	//  */
	// @PostMapping("/grab")
	// public ResponseResult driverGrab(@RequestBody DriverGrabRequest driverGrabRequest){
	//
	// 	return grabService.grab(driverGrabRequest);
	//
	// }
}
